package com.cqc.jdk8.Jio.writer;

import org.junit.Test;

import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class OutputStreamWriterTest {

    @Test
    public void f1() throws Exception {
        String filename = "C:\\Users\\cui\\Desktop\\2.txt";
        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8);
        writer.write("黄飞鸿");
        writer.write(System.lineSeparator());
        writer.write("男儿当自强");
        writer.write(System.lineSeparator());
        writer.append("李连杰");
        writer.close();
    }
    @Test
    public void f2() throws Exception {
        System.out.println(Charset.forName("UTF-8") + "," + Charset.forName("utf-8"));
        String filename = "C:\\Users\\cui\\Desktop\\1.csv";
        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8);
//        OutputStreamWriter writer2 = new OutputStreamWriter(new FileOutputStream(filename), "utf-8");//"UTF-8"="utf-8"大小写都一样
        writer.append("姓名,年龄,班级")
                .append(System.lineSeparator())
                .append("张三,15,一班")
                .append(System.lineSeparator())
                .append("李四,16,二班")
                .flush();
        writer.close();
    }
}
